package com.ruoyi.archives.service.impl;

import java.util.List;

import com.ruoyi.archives.domain.SafetyRecord;
import com.ruoyi.archives.mapper.SafetyRecordMapper;
import com.ruoyi.archives.service.ISafetyRecordService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 安全记录Service业务层处理
 *
 * @author wng
 * @date 2024-08-04
 */
@Service
public class SafetyRecordServiceImpl implements ISafetyRecordService {
    @Resource
    private SafetyRecordMapper safetyRecordMapper;

    /**
     * 查询安全记录
     *
     * @param id 安全记录主键
     * @return 安全记录
     */
    @Override
    public SafetyRecord selectSafetyRecordById(Long id) {
        SafetyRecord item = safetyRecordMapper.selectSafetyRecordById(id);
        item.setTypeName(item.getType().getTypeName());
        return item;
    }

    /**
     * 查询安全记录列表
     *
     * @param safetyRecord 安全记录
     * @return 安全记录
     */
    @Override
    public List<SafetyRecord> selectSafetyRecordList(SafetyRecord safetyRecord) {
        List<SafetyRecord> safetyRecords = safetyRecordMapper.selectSafetyRecordList(safetyRecord);
        safetyRecords.forEach(item -> {
            item.setTypeName(item.getType().getTypeName());
        });
        return safetyRecords;
    }

    /**
     * 新增安全记录
     *
     * @param safetyRecord 安全记录
     * @return 结果
     */
    @Override
    public int insertSafetyRecord(SafetyRecord safetyRecord) {
        safetyRecord.setCreateTime(DateUtils.getNowDate());
        return safetyRecordMapper.insertSafetyRecord(safetyRecord);
    }

    /**
     * 修改安全记录
     *
     * @param safetyRecord 安全记录
     * @return 结果
     */
    @Override
    public int updateSafetyRecord(SafetyRecord safetyRecord) {
        safetyRecord.setUpdateTime(DateUtils.getNowDate());
        return safetyRecordMapper.updateSafetyRecord(safetyRecord);
    }

    /**
     * 批量删除安全记录
     *
     * @param ids 需要删除的安全记录主键
     * @return 结果
     */
    @Override
    public int deleteSafetyRecordByIds(Long[] ids) {
        return safetyRecordMapper.deleteSafetyRecordByIds(ids);
    }

    /**
     * 删除安全记录信息
     *
     * @param id 安全记录主键
     * @return 结果
     */
    @Override
    public int deleteSafetyRecordById(Long id) {
        return safetyRecordMapper.deleteSafetyRecordById(id);
    }
}
